package com.contacts.service.Impl;

import com.contacts.context.BaseContext;
import com.contacts.mapper.ContactMapper;
import com.contacts.pojo.Category;
import com.contacts.pojo.Contact;
import com.contacts.service.ContactService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
@Slf4j
public class ContactServiceimpl implements ContactService {
    @Autowired
    private ContactMapper contactMapper;

    /**
     * 根据ID删除联系人
     * @param id
     */
    @Override
    public void deleteContact(Integer id) {
        contactMapper.deleteContactById(id);

    }

    /**
     * 添加联系人
     * @param contact
     * @param userId
     */
    @Override
    public void addContact(Contact contact,Integer userId) {
        contactMapper.insertContact(contact,userId);
    }

    /**
     * 修改联系人
     * @param contact
     * @param userId
     */
    @Override
    public void updateContact(Contact contact,Integer userId) {
        contactMapper.updateContact(contact,userId);
    }

    /**
     * 根据ID查询联系人
     * @param id
     * @return
     */
    @Override
    public Contact getById(Integer id) {
        Contact contact = contactMapper.findById(id);
        return contact;
    }

    /**
     * 联系人统计分析
     * @param id
     * @return
     */
    @Override
    public List<Category> getTotal(Long id) {
        return contactMapper.getTotalById(id);
    }
}
